import Vue from "vue";
import Vuex from "vuex";
import * as site from "@/api/site";
import user from "@/store/user";
import category from "@/store/category";
import product_list from "@/store/product_list";
import orderlist from "@/store/orderlist";
import role from "@/store/role";
import product from "./product";
import userlist from "@/store/userlist";
import createproduct from "./createproduct";
import action from "./action";
import categoryall from "./categoryall";
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    menuTree: [], //左侧菜单项
    // commoditycategory: {}, //商品列表
  },
  getters: {},
  mutations: {
    //为menuTree赋值
    getMenuTree(state, payload) {
      state.menuTree = payload;
    },
    // getCategory(state, payload) {
    //   state.commoditycategory = payload;
    // },
  },
  actions: {
    async getMenuTree({ commit }) {
      //发起请求并将数据传递给getMenuTree中的payload
      try {
        let { data } = await site.getMenuTree();
        commit("getMenuTree", data);
      } catch (err) {
        console.log(err);
      }
    },
    // async getCategory({ commit }) {
    //   //发起请求并将数据传递给getMenuTree中的payload
    //   try {
    //     let { data } = await site.getCategory();
    //     commit("getCategory", data);
    //   } catch (err) {
    //     console.log(err);
    //   }
    // },
  },
  modules: {
    user,
    category,
    product_list,
    orderlist,
    role,
    product,
    userlist,
    createproduct,
    action,
    categoryall,
  },
});
